{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item" >

                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="keyword" class="layui-input search" name="keyword" placeholder="商品名称/ID/画师ID"/>
                        </div>

                        <div class="layui-col-md6 layui-input-inline">
                            <select name="goods_status" lay-search="">
                                <option  value="">不限状态</option>
                                <option  value="1">上架中</option>
                                <option  value="2">已下架</option>
                            </select>
                        </div>

                        <div class="layui-col-md6 layui-input-inline">
                            <select name="goods_tuijian" lay-search="">
                                <option  value="">不限推荐状态</option>
                                <option  value="1">已推荐</option>
                                <option  value="2">未推荐</option>
                            </select>
                        </div>

                        <div class="layui-input-inline">
                            <select name="goods_type" lay-search="">
                                <option  value="">不限类目</option>
                                {foreach name="goods_type" item="v" key="k"}
                                <option  value="{$v['gt_id']}">{$v['gt_name']}</option>
                                {/foreach}
                            </select>
                        </div>

                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--操作框开始-->

                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.goods_thumb}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>

                    <!--状态显示模板-->
                    <script type="text/html" id="statBar">
                        {{# if(d.goods_status == 1){ }}
                        上架中
                        {{# } }}
                        {{# if(d.goods_status == 2){ }}
                        已下架
                        {{# } }}
                    </script>

                    <script type="text/html" id="statBar1">
                        {{# if(d.goods_tuijian == 1){ }}
                        已推荐
                        {{# } }}
                        {{# if(d.goods_tuijian == 2){ }}
                        未推荐
                        {{# } }}
                    </script>

                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('查看评价','{:url('goodsComment')}?goods_id={{d.goods_id}}')" class="btn btn-warning btn-xs m-r-xs" title="查看评价"><i class="fa fa-search">查看评价</i></a>
                        <a href="javascript:;" onclick="wk.layer_show('规格','{:url('goodsSpec')}?goods_id={{d.goods_id}}')" class="btn btn-warning btn-xs m-r-xs" title="规格"><i class="fa fa-search">规格</i></a>
                        {{# if(d.goods_tuijian == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.goods_id}}','{:url('goodsRecommend')}', '确定设置推荐？')" class="btn btn-info btn-xs m-r-xs" title="设置推荐"><i class="fa fa-arrow-up">设置推荐</i></a>
                        {{# } }}
                        {{# if(d.goods_tuijian == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.goods_id}}','{:url('goodsUnRecommend')}', '确定取消推荐？')" class="btn btn-warning btn-xs m-r-xs" title="取消推荐"><i class="fa fa-arrow-down">取消推荐</i></a>
                        {{# } }}
                        {{# if(d.goods_status == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.goods_id}}','{:url('goodsUp')}', '确定上架？')" class="btn btn-info btn-xs m-r-xs" title="上架"><i class="fa fa-arrow-up">上架</i></a>
                        {{# } }}
                        {{# if(d.goods_status == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.goods_id}}','{:url('goodsDown')}', '确定下架？')" class="btn btn-warning btn-xs m-r-xs" title="下架"><i class="fa fa-arrow-down">下架</i></a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Commongoods/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left',}
//                {type:'numbers', width: 60, title: '序号'}
                  {field: 'goods_id', width: 80, title: '商品ID', align: 'center'}
                , {field: 'goods_name', width: '', title: '商品名称', align: 'center'}
                , {field: 'goods_thumb', width: 90, title: '图片', align: 'center', templet: '#imgTpl'}
                , {field: 'goods_user_id', width: 80, title: '画师ID', align: 'center'}
                , {field: 'gt_name', width: 100, title: '商品类目', align: 'center'}
                , {field: 'goods_sail_num', width: 70, title: '销量', align: 'center'}
                , {field: 'goods_hot_sort', width: 160, title: '热门排序（可编辑）', align: 'center', edit: 'test'}
                , {field: 'goods_status', width: 80, title: '状态', align: 'center', toolbar: '#statBar'}
                , {field: 'goods_tuijian', width: 100, title: '是否推荐', align: 'center', toolbar: '#statBar1'}
                , {field: 'goods_time', width: 160, title: '创建时间', align: 'center'}
                , {fixed: 'right', width: 300, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });

        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            wk.change(data.goods_id,"{:url('updateSort')}",field,value);
        });

        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['banner_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>